﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;


namespace Negocio
{
    public class Player: PersistentObject, IDataErrorInfo, IComparable<Player>
    {
        private string name;
        private string firstLastname;
        private string secondLastname;
        private string phone;
        private string identityDocument;
        private DateTime birthDate;
        private DateTime admissionDate;
        private float weight;
        private float height;
        private string eMail;
        private string club;
        private bool enabled;
        private string photo;
        private string leg;
        private string position;

        public Player()
        {
            this.Name = "";
            this.FirstLastname = "";
            this.SecondLastname = "";
            this.Phone = "";
            this.IdentityDocument = "";
            this.BirthDate = new DateTime();
            this.AdmissionDate = new DateTime();
            this.Weight = 0;
            this.Height = 0;
            this.EMail = "";
            this.Club = "";
            this.Enabled = true;
            this.Photo = "";
            this.Leg = "";
            this.Position = "";            
        }

        public string Name
        {
            get { return this.name; }
            set { this.name = value.Trim(); }
        }

        public string FirstLastname
        {
            get { return this.firstLastname; }
            set { this.firstLastname = value.Trim(); }
        }

        public string SecondLastname
        {
            get { return this.secondLastname; }
            set { this.secondLastname = value.Trim(); }
        }

        public string Phone
        {
            get { return this.phone; }
            set { this.phone = value; }
        }
        public string IdentityDocument
        {
            get { return this.identityDocument; }
            set { this.identityDocument = value; }
        }

        public DateTime BirthDate
        {
            get { return this.birthDate; }
            set { this.birthDate = value; }
        }

        public DateTime AdmissionDate
        {
            get { return this.admissionDate; }
            set { this.admissionDate = value; }
        }

        public float Weight
        {
            get { return this.weight; }
            set { this.weight = value; }
        }

        public float Height
        {
            get { return this.height; }
            set { this.height = value; }
        }

        public string EMail
        {
            get { return this.eMail; }
            set { this.eMail = value; }
        }

        public string Club
        {
            get { return this.club; }
            set { this.club = value; }
        }

        public bool Enabled
        {
            get { return this.enabled; }
            set { this.enabled = value; }
        }

        public string Photo
        {
            get { return this.photo; }
            set { this.photo = value; }
        }

        public string Leg
        {
            get { return this.leg; }
            set { this.leg = value; }
        }

        public string Position
        {
            get { return this.position; }
            set { this.position = value; }
        }

        public string CompleteName
        {
            get { return this.firstLastname + " " + this.secondLastname + ", " + this.name;}
        }        

        public string Error
        {
            get
            {
                return null;
            }
        }

        public string this[string name]
        {
            get
            {
                string result = null;
                if (name == "IdentityDocument")
                {
                    if (this.identityDocument.ToString().Length != 8)
                    {
                        result = "Formato de la cedula debe ser de 8 digitos, sin punto ni - .";
                    }
                }
                if (name == "Name")
                {
                    if (this.name == "")
                    {
                        result = "No se ha ingresado el nombre del jugador.";
                    }
                }
                if (name == "FirstLastname")
                {
                    if (this.firstLastname == "")
                    {
                        result = "No se ha ingresado el apellido del jugador.";
                    }
                }
                if (name == "SecondLastname")
                {
                }
                if (name == "Weight")
                {
                    if (this.weight <0)
                    {

                        result = "Error al ingresar el Peso.";
                    }
                }
                if (name == "Height")
                {
                    if (this.height < 0)
                    {
                        result = "Error al ingresar la Altura";
                    }

                }
                if (name == "Club")
                {

                }
                if (name == "Leg")
                {

                }
                if (name == "Position")
                {

                }
           
                return result;
            }
        }

        public override bool Equals(object obj)
        {
            return this.IdentityDocument == (((Player)obj).IdentityDocument);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public int CompareTo(Player onePlayer)
        {
            return this.CompleteName.CompareTo(onePlayer.CompleteName);
        }
        

    }
}
